require.config({
  paths: {
      echarts: '/static/evaluate/js/echarts/dist'
    }
  });    
// 使用
require(
  [
    'echarts',
    'echarts/theme/macarons',
    'echarts/chart/pie', // 使用柱状图就加载bar模块，按需加载
    'echarts/chart/funnel',
    'echarts/chart/line',
    'echarts/chart/bar',
    'echarts/chart/wordCloud',
    'echarts/chart/gauge'
    
  ],
  function (ec,theme) {
    var teacher;
    var student;
    var advice;
    var hot_word;
    var teacher_percent;
    var student_percent;
    var year_term;
    var year_term_list;
    var student_list;
    var teacher_list;
    var hot_word_list;
    var advice_list;
    $.ajax({
        type:"POST",
        url:"/evaluate/people_count/",
        dataType:"json",
        async:false, //同步
        success:function(data){
            teacher = data[''+"teacher"+''];
            student = data[''+"student"+''];
            hot_word = data[''+"hot_word"+''];
            advice = data[''+"advice"+''];
            teacher_percent = data[''+"teacher_percent"+'']*100;
            student_percent = data[''+"student_percent"+'']*100;
            year_term = data[''+"year_term"+''];
            year_term_list = data[''+"year_term_list"+''];
            //alert(year_term_list);
            student_list = data[''+"student_list"+''];
            teacher_list = data[''+"teacher_list"+''];
            hot_word_list = data[''+"hot_word_list"+''];
            advice_list = data[''+"advice_list"+''];
        },
        error:function(){
            alert("出错了，请稍后重试！");
        }
    });
    $("#teacher_count").text(teacher);
    $("#student_count").text(student);
    $("#hot_count").text(hot_word);
    $("#advice_count").text(advice);

    // 基于准备好的dom，初始化echarts图表
    var total_number = ec.init(document.getElementById('total_number'));
    var total_teacher = ec.init(document.getElementById('total_teacher'),theme);
    var total_student = ec.init(document.getElementById('total_student'),theme);
    var total_t_s = ec.init(document.getElementById('total_t_s')); 
    // var totality_hot = ec.init(document.getElementById('totality_hot')); 
    //总体数据，历年对比
    option_total= {
    title : {
        text: '历年变化',
        subtext: year_term
    },
    tooltip : {
        trigger: 'axis'
    },
    legend: {
        data:['学生','教师','热词','建议']
    },
    toolbox: {
        show : true,
        feature : {
            dataView : {show: true, readOnly: false},
            magicType : {show: true, type: ['line', 'bar', 'stack', 'tiled']},
            restore : {show: true},
            saveAsImage : {show: true}
        }
    },
    calculable : true,
    xAxis : [
        {
            type : 'category',
            boundaryGap : false,
            data : year_term_list
        }
    ],
    yAxis : [
        {
            type : 'value'
        }
    ],
    series : [
        {
            name:'学生',
            type:'line',
            data:student_list
        },
        {
            name:'教师',
            type:'line',
            data:teacher_list
        },
       {
            name:'热词',
            type:'line',
            data:hot_word_list
        },
       {
            name:'建议',
            type:'line',
            data:advice_list
        }
    ]
};
//学生参与率统计
option_studnet = {
    tooltip : {
        formatter: "{a} <br/>{b} : {c}%"
    },
    toolbox: {
        show : true,
        feature : {
            restore : {show: true},
            saveAsImage : {show: true}
        }
    },
    series : [
        {
            name:'学生',
            type:'gauge',
            startAngle: 180,
            endAngle: 0,
            center : ['50%', '90%'],    // 默认全局居中
            radius : 150,
            axisLine: {            // 坐标轴线
                lineStyle: {       // 属性lineStyle控制线条样式
                    width: 110
                }
            },
            axisTick: {            // 坐标轴小标记
                splitNumber: 10,   // 每份split细分多少段
                length :12,        // 属性length控制线长
            },
            axisLabel: {           // 坐标轴文本标签，详见axis.axisLabel
                formatter: function(v){
                    switch (v+''){
                        case '10': return '低';
                        case '50': return '中';
                        case '90': return '高';
                        default: return '';
                    }
                },
                textStyle: {       // 其余属性默认使用全局文本样式，详见TEXTSTYLE
                    color: '#fff',
                    fontSize: 12,
                    fontWeight: 'bolder'
                }
            },
            pointer: {
                width:13,
                length: '90%',
                color: 'rgba(255, 255, 255, 0.5)'
            },
            title : {
                show : true,
                offsetCenter: [0, '-60%'],       // x, y，单位px
                textStyle: {       // 其余属性默认使用全局文本样式，详见TEXTSTYLE
                    color: '#fff',
                    fontSize: 10
                }
            },
            detail : {
                show : true,
                backgroundColor: 'rgba(0,0,0,0)',
                borderWidth: 0,
                borderColor: '#ccc',
                width: 20,
                height: 20,
                offsetCenter: [0, -20],       // 数值x, y，单位px
                formatter:'{value}%',
                textStyle: {       // 其余属性默认使用全局文本样式，详见TEXTSTYLE
                    fontSize :20
                }
            },
            data:[{value: student_percent, name: '参与率'}]
        }
    ]
};
//教师参与度
option_teacher = {
    tooltip : {
        formatter: "{a} <br/>{b} : {c}%"
    },
    toolbox: {
        show : true,
        feature : {
            restore : {show: true},
            saveAsImage : {show: true}
        }
    },
    series : [
        {
            name:'教师',
            type:'gauge',
            startAngle: 180,
            endAngle: 0,
            center : ['50%', '90%'],    // 默认全局居中
            radius : 150,
            axisLine: {            // 坐标轴线
                lineStyle: {       // 属性lineStyle控制线条样式
                    width: 110
                }
            },
            axisTick: {            // 坐标轴小标记
                splitNumber: 10,   // 每份split细分多少段
                length :12,        // 属性length控制线长
            },
            axisLabel: {           // 坐标轴文本标签，详见axis.axisLabel
                formatter: function(v){
                    switch (v+''){
                        case '10': return '低';
                        case '50': return '中';
                        case '90': return '高';
                        default: return '';
                    }
                },
                textStyle: {       // 其余属性默认使用全局文本样式，详见TEXTSTYLE
                    color: '#fff',
                    fontSize: 12,
                    fontWeight: 'bolder'
                }
            },
            pointer: {
                width:13,
                length: '90%',
                color: 'rgba(255, 255, 255, 0.5)'
            },
            title : {
                show : true,
                offsetCenter: [0, '-60%'],       // x, y，单位px
                textStyle: {       // 其余属性默认使用全局文本样式，详见TEXTSTYLE
                    color: '#fff',
                    fontSize: 10
                }
            },
            detail : {
                show : true,
                backgroundColor: 'rgba(0,0,0,0)',
                borderWidth: 0,
                borderColor: '#ccc',
                width: 20,
                height: 20,
                offsetCenter: [0, -20],       // 数值x, y，单位px
                formatter:'{value}%',
                textStyle: {       // 其余属性默认使用全局文本样式，详见TEXTSTYLE
                    fontSize :20
                }
            },
            data:[{value:teacher_percent, name: '参与率'}]
        }
    ]
};
//学生和教师比例
option_s_t = {
    tooltip : {
        trigger: 'item',
        formatter: "{a} <br/>{b} : {c} ({d}%)"
    },
    legend: {
        orient : 'vertical',
        x : 'left',
        data:['学生','教师']
    },
    toolbox: {
        show : true,
        feature : {
            dataView : {show: true, readOnly: false},
            magicType : {
                show: true, 
                type: ['pie', 'funnel'],
                option: {
                    funnel: {
                        x: '45%',
                        width: '50%',
                        funnelAlign: 'center',
                        max: 1548
                    }
                }
            },
            restore : {show: true},
            saveAsImage : {show: true}
        }
    },
    calculable : true,
    series : [
        {
            name:'比例',
            type:'pie',
            radius : ['50%', '70%'],
            itemStyle : {
              
                    normal:{ 
                      label:{ 
                        show: true, 
                        formatter: '{b} :({d}%)' 
                      }, 
                      labelLine :{show:true} 
                } ,
 
                emphasis : {
                    label : {
                        show : true,
                        position : 'center',
                        textStyle : {
                            fontSize : '30',
                            fontWeight : 'bold'
                        }
                    }
                }
            },
            data:[
                {value:student, name:'学生'},
                {value:teacher, name:'教师'}
              
            ]
        }
    ]
};
                        


total_number.setOption(option_total);
total_student.setOption(option_studnet);
total_teacher.setOption(option_teacher);
total_t_s.setOption(option_s_t);
                    
    // var key10='总体饼图';
    // var key11='总体往年对比';
    // var key12='总体热词';
    // $.ajax({
    //   type: "POST",
    //   url:"/evaluate/s_e_enviroment/",
    //   dataType: "json",
    //   success: function(data){
    //     totality_pie.setOption(data[''+key10+'']); 
    //     totality_bar.setOption(data[''+key11+'']);
    //     totality_hot.setOption(data[''+key12+'']);
    //   },
    //   error:function(){                        
    //   }
    // });         // myChart.setOption(option);
    $(".down-button").click(function(){
        $(".test").css("width","100%")
        window.print($(".right_col"));
//         html2canvas($(".right_col"), {
//          allowTaint : false,
//          onrendered:function(canvas) {
//       var contentWidth = canvas.width;
//       var contentHeight = canvas.height;

//       //一页pdf显示html页面生成的canvas高度;
//       var pageHeight = contentWidth / 592.28 * 841.89;
//       //未生成pdf的html页面高度
//       var leftHeight = contentHeight;
//       //页面偏移
//       var position = 0;
//       //a4纸的尺寸[595.28,841.89]，html页面生成的canvas在pdf中图片的宽高
//       var imgWidth = 595.28;
//       var imgHeight = 592.28/contentWidth * contentHeight;

//       var pageData = canvas.toDataURL('image/jpeg', 1.0);

//       var pdf = new jsPDF('', 'pt', 'a4');

//       //有两个高度需要区分，一个是html页面的实际高度，和生成pdf的页面高度(841.89)
//       //当内容未超过pdf一页显示的范围，无需分页
//       if (leftHeight < pageHeight) {
//       pdf.addImage(pageData, 'JPEG', 0, 0, imgWidth, imgHeight );
//       } else {
//           while(leftHeight > 0) {
//               pdf.addImage(pageData, 'JPEG', 0, position, imgWidth, imgHeight)
//               leftHeight -= pageHeight;
//               position -= 841.89;
//               //避免添加空白页
//               if(leftHeight > 0) {
//                 pdf.addPage();
//               }
//           }
//       }
//       pdf.save('content.pdf');
//   }
// })
    }); 
  }      
);
